package com.ljl.ningwei.mapper;


import com.ljl.ningwei.dto.MaterialListByJoinDTO;
import com.ljl.ningwei.entity.Material;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 物料表接口
 */
public interface MaterialMapper {

    @Select("select " +
            "id as id,\n" +
            "name as name,\n" +
            "image_urls as imageUrls,\n" +
            "category_id as categoryId,\n" +
            "product_name as productName,\n" +
            "material_count as materialCount,\n" +
            "create_time as createTime,\n" +
            "update_time as updateTime,\n" +
            "is_deleted as isDeleted " +
            "from material where id = #{id} and `is_deleted` = 0")
    Material getById(@Param("id") Long id);

    @Select("select " +
            "id as id,\n" +
            "name as name,\n" +
            "image_urls as imageUrls,\n" +
            "category_id as categoryId,\n" +
            "product_name as productName,\n" +
            "material_count as materialCount,\n" +
            "create_time as createTime,\n" +
            "update_time as updateTime,\n" +
            "is_deleted as isDeleted " +
            "from material where id = #{id}")
    Material extractById(@Param("id") Long id);

    int update(Material material);


    int insert(Material material);

    @Update(" UPDATE\n" +
            "            material\n" +
            "        SET\n" +
            "            `is_deleted` = 1\n" +
            "        WHERE  id = #{id}")
    int delete(@Param("id") Long id);

    int count();

    List<Material> getList(@Param("startIndex") Integer startIndex,
                           @Param("pageSize") Integer pageSize,
                           @Param("keyword") String keyword,
                           @Param("categoryIds")String categoryIds);




    List<MaterialListByJoinDTO> getListByJoin(@Param("startIndex") Integer startIndex,
                                              @Param("pageSize") Integer pageSize,
                                              @Param("keyword") String keyword,
                                              @Param("categoryIds")String categoryIds);


    void deleteByCategoryId(@Param("id") Long id);

}
